package com.google.code.opengw.server.support;

import com.google.code.opengw.server.domain.Route;
import com.google.code.opengw.support.OpenGWException;

public class ConfigurationUtils {

	public static boolean checkRouteURL(String url) {
		if (url.startsWith("http://") || url.startsWith("https://")
				|| url.equalsIgnoreCase("none"))
			return true;
		return false;
	}

	public static boolean checkRequestPath(String requestPath) {
		if (requestPath.startsWith("/")
				&& !requestPath.contains("//"))
			return true;
		return false;
	}

	public static void checkRouteList(Route newRoute,
			Route[] routeList) throws OpenGWException {
		for (Route route : routeList) {
			if(route == null)
				continue;
			else if (route.getRouteName().equals(newRoute.getRouteName()))
				throw new OpenGWException(OpenGWException.ROUTE_NAME_ALREADY_EXIST, route.getRouteName());
			else if(route.getRequestPath().equals(newRoute.getRequestPath()))
				throw new OpenGWException(OpenGWException.REQUEST_PATH_ALREADY_EXIST, route.getRequestPath());
		}
	}


}
